
// let prefix = 'http://localhost:8080'
import {info} from "./userinfo";

let prefix = 'http://192.168.3.34:8081'

const request = (url, method, header, data) => new Promise((resolve, reject) => {
  url = prefix + url;
  console.log(url)
  wx.request({
    url,
    method,
    data,
    header,
    success: res => resolve(res.data),
    fail: res => reject(res)
  })
})

const get = (url, params, needOpenId=false) => {
  let openid = ""
  if(needOpenId) {
    openid = info.getUserInfo().openid
  }
  return request(url, 'GET', {openid}, params)
}

const post = (url, params, needOpenId=false) => {
  let openid = ""
  if(needOpenId) {
    openid = info.getUserInfo().openid
  }
  return request(url, 'POST', {openid}, params)
}

export {
  get,
  post
}
